package com.stylefeng.guns.modular.apple_app_manage.dao;

import com.stylefeng.guns.modular.apple_app_manage.bo.ApplicationWithUsername;
import com.stylefeng.guns.modular.apple_app_manage.model.Application;
import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.stylefeng.guns.modular.push_msg.model.AppNameDO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 应用表 Mapper 接口
 * </p>
 *
 * @author GodRui
 * @since 2020-06-20
 */
public interface ApplicationMapper extends BaseMapper<Application> {
    @Select("select * from application where app_code = #{appCode};")
    Application getAppByAppCode(@Param("appCode") String appCode);

    @Select("select * from application where app_name = #{appName};")
    Application getAppByAppName(@Param("appName") String appName);

    @Select("update application set app_url = concat(#{target},'?app=', app_code) where app_url like concat(#{source},'%');")
    void updateAppWithDomain(@Param("source") String source, @Param("target") String target);

    @Select("update application set fs_image = replace(fs_image, #{oldDomain}, #{newDomain}),image = replace(image, #{oldDomain}, #{newDomain});")
    void updateAllDomainOfApplication(@Param("oldDomain") String oldDomain,
                                      @Param("newDomain") String newDomain);

    void updateAppStatus(@Param("userId") Integer userId,
                         @Param("status") Integer status);

    List<AppNameDO> findAppListByMerchantId(@Param("merchantId") Integer merchantId);
}
